package com.github.hongkaiwen.rxjava.play.problem1;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class JavaSolve extends Base {


    public static void main(String... args) throws InterruptedException, ExecutionException {
        JavaSolve javaSolve = new JavaSolve();

        //准备一个线程池来做任务
        ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("worker-%d").setDaemon(true).build();
        ThreadPoolExecutor pool = new ThreadPoolExecutor(3, 3,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>(), factory);

        Future<Integer> f1 = pool.submit(javaSolve::a);
        Future<Integer> f2 = pool.submit(javaSolve::b);
        Future<Integer> f3 = pool.submit(javaSolve::c);

        javaSolve.result((f1.get() + f2.get() + f3.get()));
    }

}
